﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>

#if 0
//删除数组中的指定数据
int main()
{
	int a[10];
	for (int i = 0; i < 10; i++)
	{
		scanf("%d", &a[i]);
	}
	int del;
	scanf("%d", &del);
	int b = 0;
	for (int i = 0; i < 10; i++)
	{
		if (a[i] != del)
		{
			a[b++] = a[i];
		}
	}
	for (int j = 0; j < b; j++)
	{
		printf("%d ", a[j]);
	}
	return 0;
}

//字符串拷贝
void my_strcpy(char* s1, char* s2)
{
	while (*s1!='\0')
	{
		s1++;
	}
	size_t count = strlen(s2);
	while (count--)
	{
		*s1 = *s2;
		s1++;
		s2++;
	}
}
int main()
{
	char str1[100] = { "hello " };
	char str2[] = { "word" };
	my_strcpy(str1, str2);
	printf("%s", str1);
	return 0;
}

//猜数字
int game(int* guess, int guessSize, int* answer, int answerSize) {
	int count = 0;
	int j = 0;
	int i = 0;
	while (guessSize--)
	{
		if (guess[j++] == answer[i++])
		{
			count++;
		}
	}
	return count;
}
void Mergearrays(int* a1, int* a2, int* a3,int n,int n1)
{
	int begin1 = 0;
	int begin2 = 0;
	int j = 0;
	while (begin1 <= n && begin2 <= n1)
	{
		if (a1[begin1] < a2[begin2])
		{
			a3[j++] = a1[begin1++];
		}
		else
		{
			a3[j++] = a2[begin2++];
		}
	}
	while (begin1 <= n)
	{
		a3[j++] = a1[begin1++];
	}
	while (begin2 <= n1)
	{
		a3[j++] = a2[begin2++];
	}
}
//合并有序数组
int main()
{
	int a1[] = { 1 ,3 ,7, 9 ,22 };
	int a2[] = { 2, 8 ,10, 17, 33, 44 };
	int n = sizeof(a1)/sizeof(int);
	int n1 = sizeof(a2)/sizeof(int);
	int a3[100];
	Mergearrays(a1, a2, a3,n-1,n1-1);
	for (int i = 0; i < (n + n1); i++)
	{
		printf("%d ", a3[i]);
	}
	return 0;
}

#include <math.h>
double* convertTemperature(double celsius, int* returnSize) {
	double* ans = (double*)malloc(sizeof(double) * 2);
	int i = 0;
	double kaifu = celsius + 273.15;
	double huafu = (celsius * 1.80) + 32.00;
	ans[i++] = roundf(kaifu * 100) / 100;
	ans[i++] = roundf(huafu * 100) / 100;
	return ans;
}
int GCD(int a, int b)
{
	while (a % b)
	{
		int c = a % b;
		a = b;
		b = c;
	}
	return b;
}
int smallestEvenMultiple(int n) {
	//先求出最大公约数 最小公倍数等于 = 两数之积/最大公约数
	int gcd = GCD(n, 2);
	return (n * 2) / gcd;
}
int main()
{
	double i = 36.50;
	double*a = convertTemperature(i, 2);
	for (int i = 0; i < 2; i++)
	{
		printf("%.2f ", a[i]);
	}
	return 0;
}

int xorOperation(int n, int start) {
	int* nums = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		nums[i] = start + 2 * i;
	}
	int count = nums[0];
	for (int i = 1; i < n; i++)
	{
		count ^= nums[i];
	}
	return count;
}
int differenceOfSum(int* nums, int numsSize) {
	int sum = 0;
	int number = 0;
	for (int i = 0; i < numsSize; i++)
	{
		number += nums[i];
	}
	for (int j = 0; j < numsSize; j++)
	{
		while (nums[j] > 0)
		{
			sum += nums[j] % 10;
			nums[j] /= 10;
		}
	}
	int big = number, small = sum;
	if (big < small)
	{
		big = sum;
		small = number;
	}
	return big - small;
}
int main()
{
	printf("%d", 1 / 2);
	return 0;
}
//判断是否为回文结构
bool isPalindrome(int x) {
	if (x < 0)
	{
		return false;
	}
	long long n = 0;
	int tmp = x;
	while (tmp)
	{
		n = tmp % 10 + n * 10;
		tmp /= 10;
	}
	return n == x;
}
//有多少⼩于当前数字的数字
int* smallerNumbersThanCurrent(int* nums, int numsSize, int* returnSize) {
	int* a = (int*)malloc(sizeof(int) * numsSize);
	*returnSize = numsSize;
	for (int i = 0; i < numsSize; i++)
	{
		int tmp = nums[i];
		int j = 0;
		for (int n = 0; n < numsSize; n++)
		{
			if (tmp > nums[n])
			{
				j++;
			}
		}
		a[i] = j;
	}
	return a;
}

int percentageLetter(char* s, char letter) {
	int a = strlen(s);
	int c = letter;
	int b = 0;
	while ((*s))
	{
		if (*s == c)
		{
			b++;
		}
		s++;
	}
	return b / a * 100;
}
int main()
{
	char s[] = "vmvvvvvzrvvpvdvvvvyfvdvvvvpkvvbvvkvvfkvvvkvbvvnvvomvzvvvdvvvkvvvvvvvvvlvcvilaqvvhoevvlmvhvkvtgwfvvzy";
	char letter = 'v';
	printf("%d", percentageLetter(s,letter));
	return 0;
}
int percentageLetter(char* s, char letter) {
	int a = strlen(s);
	double b = 0;
	while ((*s))
	{
		if ((*s) == letter)
		{
			b++;
		}
		s++;
	}
	return b / a * 100;
}

bool isSameAfterReversals(int num) {
	int sum = num;
	int n = 0;
	while (sum)
	{
		n = sum % 10 + n * 10;
		sum /= 10;
	}
	sum = n;
	n = 0;
	while (sum)
	{
		n = sum % 10 + n * 10;
		sum /= 10;
	}
	return n == num;
}
bool isUnique(char* astr) {
	int* a = (int*)calloc(26, sizeof(int));
	while ((*astr))
	{
		(a[(*astr - 'a')])++;
		astr++;
	}
	for (int i = 0; i < 26; i++)
	{
		if (a[i] > 1)
		{
			return false;
		}
	}
	return true;
}
//char* defangIPaddr(char* address) {
//	int sum = strlen(address);
//	char* ans = (char*)malloc(6 + sum - 1);
//	int j = 0;
//	while (*address)
//	{
//		if (*address == '.')
//		{
//			ans[j++] = '[';
//			ans[j++] = '.';
//			ans[j++] = ']';
//			address++;
//			continue;
//		}
//		ans[j++] = *address;
//		address++;
//	}
//	return ans;
//}
char* defangIPaddr(char* address) {
	int sum = strlen(address);
	char* ans = (char*)malloc(sum + 6 + 1);
	int j = 0;
	while (*address)
	{
		if (*address == '.')
		{
			ans[j++] = '[';
			ans[j++] = '.';
			ans[j++] = ']';
			address++;
			continue;
		}
		ans[j++] = *address;
		address++;
		if (*address == '\0')
		{
			ans[j++] = *address;
		}
	}
	return ans;
}

int main()
{
	char*a = "1.1.1.1";
	char *a1 = defangIPaddr(a);
	while (*a1)
	{
		printf("%c", *a1);
		a1++;
	}
	return 0;
}
int mostWordsFound(char** sentences, int sentencesSize) {
	int max = 0;//字符数组中最大字符的下标
	int count = 0;//字符串的中单词的个数
	int b = 0;
	for (int i = 0; i < sentencesSize; i++)
	{
		while (*sentences[i])
		{
			if ((*sentences[i]) == ' ')
			{
				b++;
			}
			sentences[i]++;
		}
		if (b > count)
		{
			count = b;
		}
		b = 0;
	}
	return count + 1;
}
int GCD(int a, int b)
{
	int c = 0;
	while ((a % b) > 0)
	{
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}
int findGCD(int* nums, int numsSize) {
	int max = 0, min = 0;
	for (int i = 1; i < numsSize; i++)
	{
		if (nums[i] > nums[max])
			max = i;
		if (nums[i] < nums[min])
			min = i;
	}
	return GCD(nums[max], nums[min]);
}
int findNumbers(int* nums, int numsSize) {
	int count = 0;//位数为偶数的个数
	int num = 0;//数组中每个数的个数
	for (int i = 0; i < numsSize; i++)
	{
		int tmp = nums[i];
		while (tmp)
		{
			num++;
			tmp /= 10;
		}
		if (num % 2 == 0)
		{
			count++;
		}
		num = 0;
	}
	return count;
}
int main()
{
	char *a[3] = { "alice and bob love leetcode","i think so too","this is great thanks very much" };
	printf("%d\n", mostWordsFound(&(*a), 3));
	printf("%d\n", GCD(10, 2));
	return 0;
}

int everyone(int a)
{
	int n = 0;
	while (a)
	{
		n = n * 10 + a % 10;
		a /= 10;
	}
	return n;
}
int* separateDigits(int* nums, int numsSize, int* returnSize) {
	int* answer = (int*)malloc(sizeof(int) * (10 ^ 5));
	int n = 0;
	int j = 0;
	for (int i = 0; i < numsSize; i++)
	{
		int tmp = everyone(nums[i]);
		while (tmp)
		{
			answer[j++] = tmp % 10;
			tmp /= 10;
			n++;
		}
	}
	*returnSize = n;
	return answer;
}
void play(int x)
{
	if (x != 0)
	{
		printf("%d", x % 10);
		play(x / 10);
	}
}
int* separateDigits(int* nums, int numsSize, int* returnSize) {
	int* answer = (int*)malloc(sizeof(int) * 100000);
	int n = 0;
	int j = 0;
	for (int i = 0; i < numsSize; i++)
	{
		int tmp = nums[i];
		int c = 0;
		int* storage = (int*)malloc(sizeof(int) * 10);
		while (tmp)
		{
			storage[c++] = tmp % 10;
			tmp /= 10;
			n++;
		}
		for (int a = c - 1; a >= 0; a--)
		{
			answer[j++] = storage[a];
		}
		c = 0;
		free(storage);
	}
	*returnSize = n;
	return answer;
}
int calculate(char* s) {
	int x = 1;
	int y = 0;
	while (*s)
	{
		if (*s == 'A')
		{
			x = 2 * x + y;
		}
		if (*s == 'B')
		{
			y = 2 * y + x;
		}
		s++;
	}
	return x + y;
}
int main()
{

	return 0;
}

char* toLowerCase(char* s) {
	int num = strlen(s);
	for (int i = 0; i < num; i++)
	{
		if (s[i] >= 'A' && s[i] <= 'Z')
		{
			s[i] += 32;
		}
	}
	return s;
}
//中枢整数
int pivotInteger(int n) {
	int mid = n / 2;
	while (1)
	{
		int a = 0;
		int b = 0;
		for (int i = 1; i <= mid; i++)
		{
			a += i;
		}
		for (int j = mid; j <= n; j++)
		{
			b += j;
		}
		if (a == b)
		{
			return mid;
		}
		if (mid == n)
		{
			return -1;
		}
		a = 0;
		b = 0;
		mid++;
	}
}
int commonFactors(int a, int b) {
	int big = a;
	int small = b;
	int count = 0;
	if (big < small)
	{
		big = b;
		small = a;
	}
	for (int i = 1; i <= small; i++)
	{
		if ((a % i == 0) && (b % i == 0))
		{
			count++;
		}
	}
	return count;
}
int main()
{
	char a = "Hello";
	toLowerCase(&a);
	return 0;
}
int finalValueAfterOperations(char** operations, int operationsSize) {
	int x = 0;
	for (int i = 0; i < operationsSize; i++)
	{
		if (operations[i][0] == 'X')
		{
			if (operations[i][1] == '-')
			{
				x -= 1;
			}
			else
			{
				x += 1;
			}

		}
		else if (operations[i][0] == '-')
		{
			x -= 1;
		}
		else
		{
			x += 1;
		}
	}
	return x;
}
//设计停车系统
typedef struct {
	int big;
	int medium;
	int small;
} ParkingSystem;
ParkingSystem* parkingSystemCreate(int big, int medium, int small) {
	ParkingSystem* Park = (ParkingSystem*)malloc(sizeof(ParkingSystem));
	Park->big = big;
	Park->medium = medium;
	Park->small = small;
	return Park;
}
bool parkingSystemAddCar(ParkingSystem* obj, int carType) {
	if (carType == 1)
	{
		if (obj->big == 0)
		{
			return false;
		}
		(obj->big)--;
		return true;
	}
	else if (carType == 2)
	{
		if (obj->medium == 0)
		{
			return false;
		}
		(obj->medium)--;
		return true;
	}
	else {
		if (obj->small == 0)
		{
			return false;
		}
		(obj->small)--;
		return true;
	}
}
void parkingSystemFree(ParkingSystem* obj) {
	obj->big = 0;
	obj->medium = 0;
	obj->small = 0;
	free(obj);
}
int main()
{
	char *operations[3] = { "--X","X++","X++" };
	finalValueAfterOperations(operations, 3);
	return 0;
}

//给定一个头节点为 head 的链表用于记录一系列核心肌群训练项目编号，
// 请查找并返回倒数第 cnt 个训练项目编号。
struct ListNode* trainingPlan(struct ListNode* head, int cnt) {
	struct ListNode* cur = head;
	int count = 0;
	while (cur)
	{
		count++;
		cur = cur->next;
	}
	int a = count - cnt;
	cur = head;
	while (a--)
	{
		cur = cur->next;
	}
	return cur;
}
//给你一个单链表的引用结点 head。链表中每个结点的值不是 0 就是 1。
// 已知此链表是一个整数数字的二进制表示形式。
int getDecimalValue(struct ListNode* head) {
	struct ListNode* cur = head;
	int count = 0;
	int tec = 0;
	while (cur)
	{
		count++;
		cur = cur->next;
	}
	cur = head;
	while (cur)
	{
		tec += (cur->val) * pow(2, count - 1);
		cur = cur->next;
		count--;
	}
	return tec;
}
//给定一个 n x n 的二进制矩阵 image ，
//先水平翻转图像然后反转图像并返回 结果 。
void Wsap(int* a, int* b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
//imageColSize 列的大小
int** flipAndInvertImage(int** image, int imageSize, int* imageColSize, int* returnSize, int** returnColumnSizes) {
	*returnSize = imageSize;
	*returnColumnSizes = imageColSize;
	for (int i = 0; i < imageSize; i++)
	{
		int left = 0;
		int right = imageSize - 1;
		while (left < right)
		{
			Wsap(&image[i][left], &image[i][right]);
			left++;
			right--;
		}
	}
	for (int j = 0; j < imageSize; j++)
	{
		for (int a = 0; a < imageSize; a++)
		{
			if (image[j][a] == 0)
			{
				image[j][a] = 1;
			}
			else
			{
				image[j][a] = 0;
			}
		}
	}
	return image;
}

int diagonalSum(int** mat, int matSize, int* matColSize) {
	int sum = 0;
	for (int i = 0; i < matSize; i++)
	{
		for (int j = 0; j < matSize; j++)
		{
			if (i == j || i + j == matSize - 1)
			{
				sum += mat[i][j];
			}
		}
	}
	return sum;
}
int main()
{
	printf("%.1f",pow(2,3));
	return 0;
}

int hammingDistance(int x, int y) {
	int r = x ^ y;
	int n = 0;
	while (r)
	{
		n++;
		r = r & (r - 1);
	}
	return n;
}
#endif
int* singleNumber(int* nums, int numsSize, int* returnSize) {
	//定义答案数组并为之分配内存
int* ans = calloc(2, sizeof(int));
int ret = 0;
int i = 0;
//计算数组中所有数异或起来的结果ret
for (i = 0; i < numsSize; i++) {
	ret ^= nums[i];
}

//从低位往⾼位遍历计算ret的⼆进制中哪⼀位是1
int pos = 0;
for (i = 0; i < 32; i++) {
	if (((ret >> i) & 1) == 1) {
		pos = i;
		break;
	}
}
//3. 分组异或
for (i = 0; i < numsSize; i++) {
	//若当前数pos位为1，作为其中⼀组对ans[0]进⾏异或操作
	if (((nums[i] >> pos) & 1) == 1) {
		ans[0] ^= nums[i];
	}
	//否则，作为另⼀组对ans[1]进⾏异或操作。
	else {
		ans[1] ^= nums[i];
	}
}
//ans[1]另⼀种计算⽅法
//ans[1]=ret^ans[0];

//更新数组⻓度
*returnSize = 2;

//返回答案数组
return ans;
}
//翻转数组
void rotate(int* nums, int numsSize, int k) {
	while (k--)
	{
		int end = nums[numsSize - 1];
		for (int i = numsSize - 2; i >= 0; i--)
		{
			nums[i + 1] = nums[i];
		}
		nums[0] = end;
	}
}
//找出消失的数
//第一种方法
int missingNumber(int* nums, int numsSize) {
	int gentle = 0;
	for (int i = 0; i <= numsSize; i++)
	{
		gentle += i;
	}
	for (int j = 0; j < numsSize; j++)
	{
		gentle -= nums[j];
	}
	return gentle;
}
//第二种方法
int missingNumber(int* nums, int numsSize) {
	int n = numsSize;
	int ret = (n + 1) * n / 2;
	for (int i = 0; i < numsSize; i++)
	{
		ret -= nums[i];
	}
	return ret;
}
//第三方法
int missingNumber(int* nums, int numsSize) {
	int ret = nums[0];
	for (int i = 1; i < numsSize; i++)
	{
		ret ^= nums[i];
	}
	for (int j = 0; j <= numsSize; j++)
	{
		ret ^= j;
	}
	return ret;
}
//删除重复数
int removeDuplicates(int* nums, int numsSize) {
	int min = nums[0], max = nums[0];
	for (int b = 0; b < numsSize; b++)
	{
		if (nums[b] < min)
		{
			min = nums[b];
		}
		if (nums[b] > max)
		{
			max = nums[b];
		}
	}
	int* tmp = (int*)calloc(max - min + 1, sizeof(int));
	for (int i = 0; i < numsSize; i++)
	{
		tmp[nums[i] - min]++;
	}
	int a = 0;
	for (int j = 0; j < max - min + 1; j++)
	{
		if (tmp[j] != 0)
		{
			nums[a++] = j + min;
		}
	}
	return a;
}
//删除重复的数
int removeElement(int* nums, int numsSize, int val) {
	int a = 0, b = numsSize - 1;
	int k = 0;
	for (int i = 0; i < numsSize; i++)
	{
		if (nums[i] == val)
		{
			k++;
		}
	}
	while (a < b)
	{
		while (a < b && nums[a] != val)
		{
			a++;
		}
		while (a < b && nums[b] == val)
		{
			b--;
		}
		nums[a++] = nums[b--];
	}
	return numsSize - k;
}
//合并有序数组
void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {
	int* tmp = malloc(sizeof(int) * (m + n));
	int j = 0;
	int begin1 = 0;
	int begin2 = 0;
	while (begin1 < m && begin2 < n)
	{
		if (nums1[begin1] <= nums2[begin2])
		{
			tmp[j++] = nums1[begin1++];
		}
		else
		{
			tmp[j++] = nums2[begin2++];
		}
	}
	while (begin1 < m)
	{
		tmp[j++] = nums1[begin1++];
	}
	while (begin2 < n)
	{
		tmp[j++] = nums2[begin2++];
	}
	memcpy(nums1, tmp, sizeof(int) * (m + n));
}
//第二种方法重最尾部开始比较谁大谁尾插到num1中
void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {
	int a = m - 1;
	int b = n - 1;
	int c = m + n - 1;
	while (a >= 0 && b >= 0)
	{
		if (nums1[a] >= nums2[b])
		{
			nums1[c--] = nums1[a--];
		}
		else
		{
			nums1[c--] = nums2[b--];
		}
	}
	while (b >= 0)
	{
		nums1[c--] = nums2[b--];
	}
}
//在数组中删除指定数
int removeElement(int* nums, int numsSize, int val) {
	int str = 0;//指向的是不为val的数
	int dest = 0;
	while (str < numsSize)
	{
		if (nums[str] == val)
		{
			str++;
		}
		else
		{
			nums[dest++] = nums[str++];
		}
	}
	return dest;
}
//删除数组中重复的数字
int removeDuplicates(int* nums, int numsSize) {
	int slow = 1, fast = 1;
	while (fast < numsSize)
	{
		if (nums[fast] == nums[fast - 1])
		{
			fast++;
		}
		else
		{
			nums[slow++] = nums[fast++];
		}
	}
	return slow;
}
//移除链表中指定的元素
struct ListNode* removeElements(struct ListNode* head, int val) {
	if (head == NULL)
	{
		return NULL;
	}
	struct ListNode* phead = NULL, * ptail = NULL, * cur = head;
	while (cur)
	{
		if (cur->val != val)
		{
			if (phead == NULL)
			{
				phead = ptail = cur;
			}
			else
			{
				ptail->next = cur;
				ptail = ptail->next;
			}
		}
		cur = cur->next;
	}
	if (ptail)
	{
		ptail->next = NULL;
	}
	return phead;
}
//翻转链表
struct ListNode* reverseList(struct ListNode* head) {
	if (head == NULL)
	{
		return NULL;
	}
	struct ListNode* prev = NULL, * cur = head;
	while (cur)
	{
		struct ListNode* Ne = cur->next;
		cur->next = prev;
		prev = cur;
		cur = Ne;
	}
	return prev;
}
//找到链表的中间节点
struct ListNode* middleNode(struct ListNode* head) {
	struct ListNode* fast = head, * slow = head;
	while (fast && fast->next)
	{
		slow = slow->next;
		fast = fast->next->next;
	}
	return slow;
}
//找到链表的倒数第k个节点
int kthToLast(struct ListNode* head, int k) {
	if (head == NULL)
	{
		return NULL;
	}
	struct ListNode* slow = head, * fast = head;
	while (k--)
	{
		fast = fast->next;
	}
	while (fast)
	{
		slow = slow->next;
		fast = fast->next;
	}
	return slow->val;
}
//合并有序链表
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
	if (list1 == NULL && list2 == NULL)
	{
		return NULL;
	}
	if (list1 == NULL && list2 != NULL)
	{
		return list2;
	}
	if (list1 != NULL && list2 == NULL)
	{
		return list1;
	}
	struct ListNode* head = malloc(sizeof(struct ListNode));
	head->val = 0;
	head->next = NULL;
	struct ListNode* s1 = list1, * s2 = list2, * patil = head;
	while (s1 && s2)
	{
		if (s1->val <= s2->val)
		{
			patil->next = s1;
			patil = patil->next;
			s1 = s1->next;
		}
		else
		{
			patil->next = s2;
			patil = patil->next;
			s2 = s2->next;
		}
	}
	while (s1)
	{
		patil->next = s1;
		patil = patil->next;
		s1 = s1->next;
	}
	while (s2)
	{
		patil->next = s2;
		patil = patil->next;
		s2 = s2->next;
	}
	return head->next;
}
//判断链表是否为回文结构
#include <cstddef>
class PalindromeList {
public:
	ListNode* Mid(ListNode* phead)
	{
		ListNode* slow = phead, * fast = phead;
		while (fast && fast->next)
		{
			slow = slow->next;
			fast = fast->next->next;
		}
		return slow;
	}
	ListNode* roat(ListNode* head)
	{
		ListNode* cur = head, * prev = NULL, * ne = NULL;
		while (cur)
		{
			ne = cur->next;
			cur->next = prev;
			prev = cur;
			cur = ne;
		}
		return prev;
	}
	bool chkPalindrome(ListNode* A) {
		ListNode* B = Mid(A);
		ListNode* c = roat(B);
		while (A && c)
		{
			if (c->val != A->val)
			{
				return false;
			}
			c = c->next;
			A = A->next;
		}
		return true;
	}
};
//判断两个链表是否有公共的节点
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
	struct ListNode* cur1 = headA, * cur2 = headB;
	int count1 = 0; int count2 = 0;
	while (cur1->next)
	{
		count1++;
		cur1 = cur1->next;
	}
	while (cur2->next)
	{
		count2++;
		cur2 = cur2->next;
	}
	struct ListNode* longcur = headA, * sortcur = headB;
	int count = abs(count1 - count2);
	if (count1 < count2)
	{
		longcur = headB;
		sortcur = headA;
	}
	while (count--)
	{
		longcur = longcur->next;
	}
	while (longcur && sortcur)
	{
		if (longcur->val == sortcur->val && longcur == sortcur)
		{
			return longcur;
		}
		longcur = longcur->next;
		sortcur = sortcur->next;
	}
	return NULL;
}
//链表是否带坏
bool hasCycle(struct ListNode* head) {
	struct ListNode* slow = head, * fast = head;
	while (fast && fast->next)
	{
		slow = slow->next;
		fast = fast->next->next;
		if (slow == fast)
		{
			return true;
		}
	}
	return false;
}
//找出链表环节点
struct ListNode* hasCycle(struct ListNode* head) {
	struct ListNode* slow = head, * fast = head;
	while (fast && fast->next)
	{
		slow = slow->next;
		fast = fast->next->next;
		if (slow == fast)
		{
			return fast;
		}
	}
	return NULL;
}
struct ListNode* detectCycle(struct ListNode* head) {
	struct ListNode* Mid = hasCycle(head);
	struct ListNode* cur = head;
	if (Mid == NULL)
	{
		return NULL;
	}
	while (Mid != cur)
	{
		Mid = Mid->next;
		cur = cur->next;
	}
	return Mid;
}

//括号匹配问题
bool isValid(char* s) {
	//创建一个栈
	Stack a;
	StackInit(&a);
	while (*s)
	{
		if (*s == '(' || *s == '{' || *s == '[')
		{
			StackPush(&a, *s);
		}
		else
		{
			if (StackEmpty(&a))
			{
				return false;
			}
			char tmp = StackTop(&a);
			StackPop(&a);
			if ((tmp == '(' && *s != ')')
				|| (tmp == '{' && *s != '}')
				|| (tmp == '[' && *s != ']'))
			{
				return false;
			}
		}
		s++;
	}
	if (!StackEmpty(&a))
	{
		return false;
	}
	return true;
}
//用栈实现队列
MyQueue* myQueueCreate() {
	MyQueue* obj = (MyQueue*)malloc(sizeof(MyQueue));
	StackInit(&(obj->push));
	StackInit(&(obj->out));
	return obj;
}

void myQueuePush(MyQueue* obj, int x) {
	StackPush(&(obj->push), x);
}

int myQueuePeek(MyQueue* obj) {
	if (StackEmpty(&(obj->out)))
	{
		while (!StackEmpty(&(obj->push)))
		{
			StackPush(&(obj->out), StackTop(&(obj->push)));
			StackPop(&(obj->push));
		}
		return StackTop(&(obj->out));
	}
	else
	{
		return StackTop(&(obj->out));
	}
}

int myQueuePop(MyQueue* obj) {
	int count = myQueuePeek(obj);
	StackPop(&(obj->out));
	return count;
}

bool myQueueEmpty(MyQueue* obj) {
	if (StackEmpty(&(obj->push)) && StackEmpty(&(obj->out)))
	{
		return true;
	}
	return false;
}

void myQueueFree(MyQueue* obj) {
	StackDestroy(&(obj->push));
	StackDestroy(&(obj->out));
	free(obj);
	obj = NULL;
}

//环形队列问题
typedef struct {
int* a;//指向队列的指针
int phead;//指向队列的开头用来出队列
int tail;//指向队列的结尾用来入队列
int k;//队列中元素的个数
} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) {
	MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
	obj->a = (int*)malloc(sizeof(int) * (k + 1));
	obj->phead = 0;
	obj->tail = 0;
	obj->k = k;
	return obj;
}
bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
	return obj->phead == obj->tail;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
	return obj->phead == ((obj->tail) + 1) % ((obj->k) + 1);
}
bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
	if (myCircularQueueIsFull(obj))
	{
		return false;
	}
	obj->a[obj->tail] = value;
	obj->tail = (obj->tail + 1) % (obj->k + 1);
	return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
	if (myCircularQueueIsEmpty(obj))
	{
		return false;
	}
	obj->phead = (obj->phead + 1) % (obj->k + 1);
	return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
	if (myCircularQueueIsEmpty(obj))
	{
		return -1;
	}
	return obj->a[obj->phead];
}

int myCircularQueueRear(MyCircularQueue* obj) {
	if (myCircularQueueIsEmpty(obj))
	{
		return -1;
	}
	return obj->a[(obj->tail - 1 + obj->k + 1) % (obj->k + 1)];
}

void myCircularQueueFree(MyCircularQueue* obj) {
	free(obj->a);
	obj->a = NULL;
	obj->phead = 0;
	obj->tail = 0;
	free(obj);
	obj = NULL;
}
//队列实现栈
typedef struct {
	Queue q1;
	Queue q2;
} MyStack;


MyStack* myStackCreate() {
	MyStack* obj = (MyStack*)malloc(sizeof(MyStack));
	QueueInit(&(obj->q1));
	QueueInit(&(obj->q2));
	return obj;
}

void myStackPush(MyStack* obj, int x) {
	if (!QueueEmpty(&(obj->q1)))
	{
		QueuePush(&(obj->q1), x);
	}
	else {
		QueuePush(&(obj->q2), x);
	}
}

int myStackPop(MyStack* obj) {
	if (!QueueEmpty(&(obj->q1)))
	{
		while (QueueSize(&(obj->q1)) > 1)
		{
			QueuePush(&(obj->q2), QueueFront(&(obj->q1)));
			QueuePop(&(obj->q1));
		}
		int a = QueueFront(&(obj->q1));
		QueuePop(&(obj->q1));
		return a;
	}
	else
	{
		while (QueueSize(&(obj->q2)) > 1)
		{
			QueuePush(&(obj->q1), QueueFront(&(obj->q2)));
			QueuePop(&(obj->q2));
		}
		int b = QueueFront(&(obj->q2));
		QueuePop(&(obj->q2));
		return b;
	}
}

int myStackTop(MyStack* obj) {
	if (!QueueEmpty(&(obj->q1)))
	{
		return QueueBack(&(obj->q1));
	}
	else {
		return QueueBack(&(obj->q2));
	}
}

bool myStackEmpty(MyStack* obj) {
	if (QueueEmpty(&(obj->q1)) && QueueEmpty(&(obj->q2)))
	{
		return true;
	}
	return false;
}

void myStackFree(MyStack* obj) {
	QueueDestroy(&(obj->q1));
	QueueDestroy(&(obj->q2));
	free(obj);
	obj = NULL;
}